<?php

class Model_Doctor extends PhalApi_Model_NotORM {

    public function login($username,$password)
    {

        $doctor= $this->getORM();
        $rs=$doctor ->select('id')
            ->where(array('UserName'=>$username,'PassWord'=>$password))
            ->fetch();

        //var_dump($doctor);

        return $rs;

    }
    public function listDoctors($visible,$status,$depart,$hospital)
    {

        $doctor= $this->getORM();
        $rs=$doctor ->select('id as DoctorId','Name','Hospital','Depart','DepartName','Status','PhoneNumber','Visible','Location','Lng','Lat');
        if(!empty($visible)){
            $doctor->where(array('Visible'=>$visible));
        }
        if(!empty($status)){
            $doctor->where(array('Status'=>$status));
        }
        if(!empty($$depart)){
            $doctor->where(array('Hospital'=>$hospital));
        }
        if(!empty($hospital)){
            $doctor->where(array('DepartName'=>$depart));
        }

        $doctor->fetchRows();
        //var_dump($doctor)
        return $rs;

    }
    public function listDoctorsLocation()
    {

        $doctor= $this->getORM();
        $rs=$doctor
            ->select('id','Name','Hospital','DepartName','Status','Location','Lng','Lat')
            ->where('')
            ->fetchRows();
        //var_dump($doctor);

        return $rs;

    }

    public function isExist($input,$type)
    {
        if($type=='username'){
        $doctor=$this->getORM();
        $rs=$doctor->select('*')
            ->where('UserName=?',$input)
            ->count();
        //var_dump($rs);
        return $rs;
        }
    if($type=='doctor_id'){
        $doctor=$this->getORM();
        $rs=$doctor->select('*')
            ->where('id=?',$input)
            ->count();
        //var_dump($rs);
        return $rs;

}
        else{
            return null;
        }
    }
    protected function getTableName($id) {
        return 'Doctor';
    }
    protected function getTableKey($table) {
        return 'id';
    }
}